﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- jsp文件头和头部 -->
<%@ include file="../main/main_top.jsp"%>
</head>
<body>
	<div class="container-fluid" id="main-container">
		<div id="breadcrumbs">
			<ul class="breadcrumb">
				<li><i class="icon-home"></i> <a>权限管理</a> <span class="divider">
						<i class="icon-angle-right"></i>
				</span></li>
				<li class="active">角色管理</li>
			</ul>
			<!--.breadcrumb-->
		</div>
		<!--#breadcrumbs-->
		<div class="page-header position-relative">
			<div>
				&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-small btn-success"
					onclick="addRole();">新增</a>
			</div>
		</div>

		<div id="page-content">
			<div class="row-fluid">
				<div class="row-fluid">
					<table id="table_report"
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th class="center">序号</th>
								<th>角色名称</th>
								<th style="width: 155px;" class="center">操作</th>
							</tr>
						</thead>
						<c:choose>
							<c:when test="${not empty roleList}">
								<c:forEach items="${roleList}" var="var" varStatus="vs">
									<tr>
										<td class='center' style="width: 30px;">${vs.index+1}</td>
										<td id="roleNameTd${var.roleid }">${var.rolename }</td>
										<td style="width: 155px;">
											<a class="btn btn-mini btn-purple" onclick="authPrivileges('${var.roleid }');"><i class="icon-pencil"></i>角色权限</a> 
											<a class='btn btn-mini btn-info' title="编辑" onclick="editRole('${var.roleid }');"> <i class='icon-edit'></i></a> 
											<a class='btn btn-mini btn-danger' title="删除" onclick="delRole('${var.roleid }','c','${var.rolename }');"> <i class='icon-trash'></i> </a>
										</td>
									</tr>
								</c:forEach>
								<!-- <tr>
									<td colspan="100" class="center">您无权查看</td>
								</tr> -->
							</c:when>
							<c:otherwise>
								<tr>
									<td colspan="100" class="center">没有相关数据</td>
								</tr>
							</c:otherwise>
						</c:choose>
					</table>

				</div>
				<!-- PAGE CONTENT ENDS HERE -->
			</div>
			<!--/row-->

		</div>
		<!--/#page-content-->
	</div>
	<!--/.fluid-container#main-container-->

	<!-- 返回顶部  -->
	<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse"> <i
		class="icon-double-angle-up icon-only"></i>
	</a>

	<!-- 引入 -->
	<script type="text/javascript" src="static/1.9.1/jquery.min.js"></script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");
	</script>
	<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
	<script type="text/javascript" src="static/js/ace.min.js"></script>
	<script type="text/javascript" src="static/js/bootbox.min.js"></script>
	<!-- 确认窗口 -->
	<!-- 引入 -->

	<!--引入弹窗组件start-->
	<script type="text/javascript" src="plugins/js/attention/zDialog/zDrag.js"></script>
	<script type="text/javascript" src="plugins/js/attention/zDialog/zDialog.js"></script>

	<!--引入弹窗组件end-->
	<script type="text/javascript">
		$(top.hangge());

		//新增职位
		function addRole() {
			top.jzts();
			var diag = new top.Dialog();
			diag.Drag = true;
			diag.Title = "新增角色";
			diag.URL = '<%=basePath%>/newrole/toAdd.do';
			diag.Width = 222;
			diag.Height = 90;
			diag.CancelEvent = function() { //关闭事件
				if (diag.innerFrame.contentWindow.document
						.getElementById('centerOfMainFrame').style.display == 'none') {
					top.jzts();
					setTimeout("self.location.reload()", 100);
				}
				diag.close();
			};
			diag.show();
		}

		//修改
		function editRole(roleid) {
			top.jzts();
			var diag = new top.Dialog();
			diag.Drag = true;
			diag.Title = "编辑角色";
			diag.URL = '<%=basePath%>/newrole/toEdit.do?roleid=' + roleid;
			diag.Width = 222;
			diag.Height = 90;
			diag.CancelEvent = function() { //关闭事件
				if (diag.innerFrame.contentWindow.document
						.getElementById('centerOfMainFrame').style.display == 'none') {
					top.jzts();
					setTimeout("self.location.reload()", 100);
				}
				diag.close();
			};
			diag.show();
		}

		//删除
		function delRole(roleid, msg, rolename) {
			bootbox.confirm("确定要删除[" + rolename + "]吗?", function(result) {
				if (result) {
					var url = "<%=basePath%>/newrole/delete.do?roleid=" + roleid + "&guid="
							+ new Date().getTime();
					$.get(url, function(data) {
						if (data == "success") {
							if (msg == 'c') {
								top.jzts();
								document.location.reload();
							} else {
								top.jzts();
								window.location.href = "newrole.do";
							}
						} else if (data == "false2") {
							bootbox.dialog("删除失败，请先删除此角色与用户的关联关系!", [ {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback" : function() {
									//Example.show("great success");
								}
							} ]);
						} else if (data == "false3") {
							bootbox.dialog("删除失败，请先删除此角色与模块的关联关系!", [ {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback" : function() {
									//Example.show("great success");
								}
							} ]);
						}
					});
				}
			});
		}
	</script>

	<script type="text/javascript">
		//菜单权限
		function authPrivileges(roleid) {
			top.jzts();
			var diag = new top.Dialog();
			diag.Drag = true;
			diag.Title = "模块权限";
			diag.URL = '<%=basePath%>/newrole/authModuleAndOper.do?roleid=' + roleid;
			diag.Width = 280;
			diag.Height = 670;
			diag.CancelEvent = function() { //关闭事件
				diag.close();
			};
			diag.show();
		}
	</script>
</body>
</html>

